Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently I have been asking the wrong questions to my problems. I now understand that I must use some sort of listbox or listview ect when comparing MD5 hash to my current file directory Maybe true maybe not. I am interested in knowing if there is a quicker way to populate a directories contents in the above objects by using API or some other function?


any advice is well appricated thank you in advance and sorry for any misleading questions due to my inexpierence.
Posted

How many files are we talking about here? How are you doing it right now? The System.IO name space contains the stuff you need.

C#
DirectoryInfo info = new DirectoryInfo(myPath);
FileSystemInfo[] infos = info.GetFileSystemInfos("*.*", true);


That code will get all files (in all sub-folders) inside the named path(myPath). Putting the retrieved info into a ListBox is trivial.
 
Share this answer
 
Comments
Dale 2012 18-Feb-11 6:42am    
thank you for the code example but I am aware of the system.IO name space but my question was relating to a quicker way of populating files in a textbox, listbox, checkedlistbox by another means or by using this method along with something else because at present time I have 320000 + files in one root directory and it takes 5mins + to populate in my listbox. My computer is quite fast so its not anything to do with system performance..

do you have any out of the box methods or any ideas to help?
thanks in advance :)
#realJSOP 18-Feb-11 10:47am    
Unfortunately, 320,000 files is gonna take a long time, regardless of what you do. There is no way around it, beyond installing some sort of filtering mechanism. You could do a linq query on the colleciton of foud files and just show those that meet some requirement, such as changing the list while the user types a filename.
Sergey Alexandrovich Kryukov 18-Feb-11 10:51am    
I think I know what can help, see my answer.
--SA
May be my past answer will give you the idea: Need Some Expert Help With Treeview Scan Please[^]?

The answer is about the tree view, but think of it as an idea. In UI, you usually don't need to see all sub-directories at once. If so, you don't have to scan and load them all at once. You can only fetch the file structure data about the views currently presented on-screen. In this case, the time required to fetch all data per request can be short enough.

Even though the total time of fetching file information becomes longer (because the some portion of data is repeated again and again per each user request), the user experience is more important; few extra milliseconds per click on some UI control is not noticeable.

Even if you use a list instead of tree view, you still can use the same idea: you can have Next/Previous controls to show only partial data every time.

Also, mind you: if your try to get all directory tree at once from some really big directories, you can simply deplete you memory, even without any UI presentation — disks are bigger than RAM!

Sorry if it is not very relevant: unfortunately you didn't share enough detail on you ultimate goals and criteria (I remember you shared some, but I still cannot clearly see your design ideas).

—SA
 
Share this answer
 
v3
Comments
Dale 2012 18-Feb-11 17:33pm    
Ok I have just one more question at this point. Seeing as how the treeview populates the folders and folders within them is it not possible to scan through the tree nodes the same as you would files in a listbox?
Sergey Alexandrovich Kryukov 18-Feb-11 20:48pm    
Dale,

I don't see principal difference, in the terms being discussed. I did not realize from your reply which exactly controls you want to have, but let's quickly talk two views:

1) Tree view: behavior is designed as I described in the reference above. It shows "virtual" view on the directory tree: it looks exactly as if the whole directory was loaded on it one-to-one, but technically only the part of file information is shown, only to show the content of currently expanded nodes.

2) List: if can look exactly as if you use Explorer in Tree or Detail view; showing only "current" directory in a single level. When you hit Enter (dbl-click) of a folder, it goes deeper, on backspace goes "../" (up), etc. You may add some navigation controls to it, like buttons. Optionally, even on one level you can show only parts of items, navigating using Next/Previous controls (typical for Web UI).

In both cases, you don't generally show and don't load all file structure at once, don't keep it all in memory, you dynamically load/unload some portions of data. Additionally, you may want to filter out some of objects (by extensions, attributes, etc., according to what is of interest for your application).

Using either schema, you can really provide very good responsiveness and avoid out-of-memory condition, I'll guarantee that. :-)

--SA
Dale 2012 18-Feb-11 21:44pm    
Ok Im following you and understand that loading directories as needed or as requested will improve the feel of the program but how can this be acheived when you need to scan a directory? Is there any msdn that describes how to do this?

thank you again for your patients.
Sergey Alexandrovich Kryukov 18-Feb-11 22:04pm    
Yes. No problem. Option #1: see John's answer above, #2: System.IO.Directory.GetFiles, System.IO.Directory.GetDirectories. Look around System.IO, just in case.
--SA
Dale 2012 18-Feb-11 21:48pm    
maybe you can help by providing a small solution if its something you completely are willing to do. I would be very thankfull to see how to check files md5 hash from dir treeview.

it would put my questions and mind to rest as I have not had much rest trying to figure this out.
Hope this[^] might help you.
 
Share this answer
 
Comments
Dale 2012 18-Feb-11 6:43am    
not a bad site for someone who wants to learn about recrusion but in my case I need something different completely

thanks for your help anyways!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900